<?php
//	session_start();
	require("/wamp/www/bbs/common/Common.php");
	//实例化Model类
	$model = new Model('bbs_user');
	$_GET['type'] = isset($_GET['type']) ? $_GET['type'] : '';
	//获取提交的信息
	$_POST['username'] = trim(isset($_POST['username']) ? $_POST['username'] : '');
	$_POST['password'] = trim(isset($_POST['password']) ? $_POST['password'] : '');
	$_POST['pass_tow'] = trim(isset($_POST['pass_tow']) ? $_POST['pass_tow'] : '');
	$_POST['qx'] = trim(isset($_POST['qx']) ? $_POST['qx'] : '');
	$_POST['rtime'] = time();
	//判断用户名及密码是否是空
	if(empty($_POST['username']) || empty($_POST['password'])) {
		echo "<script>alert('用户名或密码不能为空!');window.history.back(-1);</script>";
		return;
	}
	$_POST['password'] = md5($_POST['password']);
	//判断GET条件进行相应操作
	switch ($_GET['type']) {
		//添加操作
		case 'insert':
			$res = $model->insert();
			if($res > 0) {
				echo "<script>
						alert('添加成功');
						window.location.href='../main_info.php';
					</script>";
			} else {
				echo "<script>alert('添加失败！');window.history.back(-1);</script>";
				return;
			}
			break;
		//删除操作
		case 'del':
			$id = $_GET['id'];
			$row = $model -> del($id);
			if($row > 0) {
				echo "<script>
						alert('删除成功！');
						window.location.href='../main_list.php';
					</script>";
				return;
			}
			break;
			
		//修改操作
		case 'edit':

			$path = "/wamp/www/bbs/public/uploads/";
			$typelist = array("image/jpeg","image/png","image/gif");
			
			//执行上传并判断
            $res = fileUpload($_FILES['pic'],$path,$typelist);
            if(!$res['error']){
                die("相册图片上传失败！原因：".$res['info']);
            }
			
			$_POST['telphone'] = trim($_POST['telphone']);
			$_POST['email'] = trim($_POST['email']);
			$_POST['pic'] = $res['info'];
			
			$num = $model->update();
			if($num > 0) {
				echo "<script>
						alert('修改成功！');
						window.location.href='../main_list.php';
					</script>";
			}
			
			break;
			
		default:
			echo "<script>
						window.location.href='../index.php';
				</script>";
			break;
	}
	